Update and Add Data

Pre-Create Blank Rows in Table Control

Description
This customization shows how to pre-create a few blank entries for the child tables.
Variables
Table Name
Select the name of the database table
TableControl
Select a table control
Applies to
TableControl class
Code
 
/// 
/// This method will add three records rows in the table control
/// 
public Boolean IsLoadDataCalled = false;
public override void LoadData()
{
    // Call base.LoadData()
    base.LoadData();
    if (!this.Page.IsPostBack && !IsLoadDataCalled) 
    {
        IsLoadDataCalled = true;
        ArrayList list;
        if ((DataSource == null))
        {
            list = new ArrayList();
        }
        else
        {
            list = new ArrayList(this.DataSource);        

        }
        int i;
        for (i = 0; i < 3; i++)
        {
            // To insert rows at the end of the table control
            list.Add(new ${${Table Name}RecordClassName}());  

            // To insert rows at the top of the table control
            // list.Insert(i, new ${${Table Name}RecordClassName}());               
        }                  
        this.DataSource = (${${Table Name}RecordClassName}[])(list.ToArray(typeof(${${Table Name}RecordClassName})));
    }
}
     

Terms of Service Privacy Statement